package JXY02.Day03;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 要求用户输入若干员工信息，格式为：
 * name,age,gender,salary,hiredate;name,age,gender,salary,hiredate;....
 * 例如:
 * 张三,25,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;...
 * 然后将每个员工信息解析成Emp对象。并存入到一个集合中。
 * 然后循环集合，输出每一个员工信息(输出使用toString返回的字符串)
 * 然后输出每个员工的转正仪式日期。
 * 转正仪式日期为:入职3个月的当周周五
 *
 */
public class Text06 {
    String str = "张三,30,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;";
    private List<Text03Emp> getList(){

        //获得每个员工的字符串
        String s1 = ";";
        String[] workers = str.split(s1);

        List<String> arrayList = new ArrayList<>();
        List<Text03Emp> empList = new ArrayList<>();

        for (int i=0; i<workers.length; i++){
            arrayList.add(workers[i]);

        }

        for (int i=0; i<arrayList.size(); i++){
            //获得每个员工的每项值的字符串
            String workers_i = arrayList.get(i);
            String[] worker_i = workers_i.split(",");
            //将值给emp
            Text03Emp emp = new Text03Emp(worker_i[0],worker_i[1],worker_i[2],worker_i[3],worker_i[4]);
            empList.add(emp);
        }
        return empList;
    }

    private Date getDate(Text03Emp emp) throws ParseException {
        String date = emp.getE_hiredate();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date hiredate = format.parse(date);
        return hiredate;
    }

    public static void main(String[] args) throws ParseException {
        Text06 text06 = new Text06();
        List<Text03Emp> emp = new ArrayList<>();
        emp = text06.getList();

        for (Text03Emp emp1 : emp){
            System.out.println(emp1.toString());
            Date date = text06.getDate(emp1);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.MONTH,3);
            calendar.set(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);
            System.out.println(calendar.getTime());
        }

    }

}
